<template>
  <el-dialog
    :title="!dataForm.paperId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="论文名称" prop="paperName">
      <el-input v-model="dataForm.paperName" placeholder="论文名称"></el-input>
    </el-form-item>
    <el-form-item label="教师姓名" prop="teacherId">
      <!-- <el-input v-model="dataForm.teacherId" placeholder="教师姓名"></el-input> -->
      <el-select v-model="dataForm.teacherId" filterable placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="期刊名称" prop="periodicalName">
      <el-input v-model="dataForm.periodicalName" placeholder="期刊名称"></el-input>
      
    </el-form-item>
    <el-form-item label="发表时间" prop="publishTime">
      <!-- <el-input v-model="dataForm.publishTime" placeholder="发表时间"></el-input> -->
      <el-date-picker
      v-model="dataForm.publishTime"
      type="datetime"
      placeholder="发表时间">
    </el-date-picker>
    </el-form-item>
    <el-form-item label="期刊级别" prop="periodicalLevelId">
      <!-- <el-input v-model="dataForm.periodicalLevel" placeholder="期刊级别"></el-input> -->
      <el-select v-model="dataForm.periodicalLevel" placeholder="期刊级别">
    <el-option
      v-for="item in periodicals"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="索引情况" prop="indexesId">
      <!-- <el-input v-model="dataForm.indexesId" placeholder="索引情况"></el-input> -->
      <el-select v-model="dataForm.indexes" placeholder="期刊级别">
    <el-option
      v-for="item in indexs"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
         indexs: [{
          value: 'SCI',
          label: 'SCI'
        }, {
          value: 'SSCI',
          label: 'SSCI'
        }, {
          value: 'A&HCI',
          label: 'A&HCI'
        }, {
          value: 'ISTP',
          label: 'ISTP'
        }, {
          value: 'ISSHP',
          label: 'ISSHP'
        }],
        periodicals: [{
          value: '省级期刊',
          label: '省级期刊'
        }, {
          value: '国家级期刊',
          label: '国家级期刊'
        }, {
          value: '核心期刊',
          label: '核心期刊'
        }, {
          value: '外文期刊',
          label: '外文期刊'
        }],
        options:[],
        visible: false,
        dataForm: {
          paperId: 0,
          paperName: '',
          teacherId:'',
          periodicalName: '',
          publishTime: '',
          periodicalLevel: '',
          indexes: ''
        },
        dataRule: {
          paperName: [
            { required: true, message: '论文名称不能为空', trigger: 'blur' }
          ],
          periodicalName: [
            { required: true, message: '期刊名称不能为空', trigger: 'blur' }
          ],
          teacherId: [
            { required: true, message: '教师名称不能为空', trigger: 'blur' }
          ],
          publishTime: [
            { required: true, message: '发表时间不能为空', trigger: 'blur' }
          ],
          periodicalLevel: [
            { required: true, message: '期刊级别不能为空', trigger: 'blur' }
          ],
          indexes: [
            { required: true, message: '索引情况不能为空', trigger: 'blur' }
          ]
        }
      }
    },
     created(){
      this.getteacherInfo()
    },
    methods: {
       getteacherInfo(){
        // 获取教师基本信息
        this.$http({
        url: this.$http.adornUrl('/teacherservice/teachertitle/teacher/info'),
        method: 'get',
        params: this.$http.adornParams({})
        }).then(({data}) => {
          console.log(data)
          this.options=data.data
          console.log("jdvnd",this.options)
        })
      },
      init (id) {
        this.dataForm.paperId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.paperId) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teacherpaper/info/${this.dataForm.paperId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.paperName = data.teacherPaper.paperName
                this.dataForm.periodicalName = data.teacherPaper.periodicalName
                this.dataForm.publishTime = data.teacherPaper.publishTime
                this.dataForm.teacherId = data.teacherPaper.teacherId
                this.dataForm.periodicalLevel = data.teacherPaper.periodicalLevel
                this.dataForm.indexes = data.teacherPaper.indexes
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teacherpaper/${!this.dataForm.paperId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'paperId': this.dataForm.paperId || undefined,
                'paperName': this.dataForm.paperName,
                'periodicalName': this.dataForm.periodicalName,
                'teacherId':this.dataForm.teacherId,
                'publishTime': this.dataForm.publishTime,
                'periodicalLevel': this.dataForm.periodicalLevel,
                'indexes': this.dataForm.indexes
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            
            })
          }
        })
      }
    }
  }
</script>
